﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo3
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var hand = "";
            Console.Write("请输入您的手势(石头/剪刀/布)，您出：");
            hand = Console.ReadLine();
            int user = 0, com = 0;
            for (; (hand== "石头"|| hand == "剪刀"|| hand == "布")&&!(user>4||com>4); hand = Console.ReadLine())
            {              
                //首先生成一个随机数 rndNum保存一个0 1 2的随机整数
                // 0表示石头 1剪刀 2布
                var rndNum = new Random().Next(0, 3);
                if (rndNum == 0)
                    Console.WriteLine("电脑出：石头");
                else if (rndNum == 1)
                    Console.WriteLine("电脑出：剪刀");
                else
                    Console.WriteLine("电脑出：布");

                //判定谁赢？ 
                var userWin = (hand == "石头" && rndNum == 1) || (hand == "剪刀" && rndNum == 2) || (hand == "布" && rndNum == 0);
                var comWin = (hand == "布" && rndNum == 1) || (hand == "石头" && rndNum == 2) || (hand == "剪刀" && rndNum == 0);

                if (userWin)
                    Console.WriteLine("我赢了,长得帅又有实力！我({0}) vs 电脑({1})", ++user, com);
                else if (comWin)
                    Console.WriteLine("电脑赢了，太卑鄙了！我({0}) vs 电脑({1})", user, ++com);
                else
                    Console.WriteLine("打平！不算再来。我({0}) vs 电脑({1})", user, com);

                if (user < 4 && com < 4)
                    Console.Write("请输入您的手势(石头/剪刀/布)，您出：");
                else
                    //退出循环
                    break;
            }
            Console.WriteLine("我({0}) vs 电脑({1})，{2}", user, com, user>com?"我赢":"电脑赢");
            Console.ReadKey();
        }
    }
}
